# coding=utf-8
__author__ = 'st316'
'''
print a matrix in 45 degree:
eg:                 output:
1 2 3               3
4 5 6               2 6
7 8 9               1 5 9
                    4 8
                    7
'''


class Solution:
    # @param matrix, a list of lists
    # @return nothing
    def print45(self, matrix):
        width = len(matrix)
        height = len(matrix[0])

        #右上和左下来打印
        for level in xrange(height + width - 1, -1, -1):  # 一共循环height + width - 1次，打印这么多行
            # width - level > 0 来判断是否转入左下
            x = width - level - 1 if width - level > 0 else 0
            y = 0 if width - level > 0 else level - width + 1

            while x < width and y < height:
                print matrix[x][y],
                print ' ',
                x += 1
                y += 1
            print


if __name__ == '__main__':
    s = Solution()
    m = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
    s.print45(m)